package com.abc.intellihome.service;

import com.abc.intellihome.domain.Furniture;
import com.abc.intellihome.mapper.FurnitureMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FurnitureService {

    @Autowired
    private FurnitureMapper furnitureMapper;

    public List<Furniture> chatAll(String username){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("username",username);
        List<Furniture> furnitureList = furnitureMapper.selectList(wrapper);

        return furnitureList;
    }

    public int changeOnOff(Furniture furniture){
        UpdateWrapper<Furniture> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("name", furniture.getName()).eq("username", furniture.getUsername());
        int result = furnitureMapper.update(furniture, updateWrapper);


        return result;
    }

    public int addFurniture(Furniture furniture){
        int result =  furnitureMapper.insert(furniture);

        return result;
    }

    public int removeFurniture(Furniture furniture){
        QueryWrapper<Furniture> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",furniture.getName()).eq("username",furniture.getUsername());
        int result=furnitureMapper.delete(queryWrapper);
        return result;
    }



}
